#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>

using namespace std;

bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
    stack<int> s;
    int l = 0;
    for (int i = 0; i < popped.size(); i++)
    {
        if (s.empty() || s.top() != popped[i])
        {
            while (l < pushed.size() && (s.empty() || s.top() != popped[i]))
            {
                s.push(pushed[l++]);
            }
        }
        if(s.top() == popped[i])
            s.pop();
    }
    return s.empty();
}

class com
{
public:
    bool operator()(string s1, string s2)
    {
        string res1 = s1 + s2, res2 = s2 + s1;
        return res1 < res2;
    }
};

string minNumber(vector<int>& nums) {
    vector<string> vs;
    for (auto it : nums)
        vs.push_back(to_string(it));

    sort(vs.begin(), vs.end(), com());
    string res;
    for (auto it : vs)
        res += it;

    return res;
}

int main()
{
    vector<int> v = { 3,30,34,5,9 };
    /*vector<int> v1 = { 1,2,3,4,5 };
    vector<int> v2 = { 4,5,3,2,1 };*/
    //cout << validateStackSequences(v1, v2);
    cout << minNumber(v);
    return 0;
}